//
//  DiscoverViewController.m
//  Dear
//
//  Created by 陈俊俊 on 15/7/11.
//  Copyright (c) 2015年 陈俊俊. All rights reserved.
//

#import "DiscoverViewController.h"
#import "DiscoverCell.h"
#import "DiscoverModel.h"
#import "GameViewController.h"
#import "ShootViewController.h"
@interface DiscoverViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView *_tableView;
    NSMutableArray *_dataArr;
}
@end


@implementation DiscoverViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self createTitleViewWith:@"发现"];
    //初始化数据
    [self initData];
    //创建tableview
    [self createTableView];
}
#pragma mark - 初始化数据
- (void)initData
{
    _dataArr = [[NSMutableArray alloc]init];
//    DiscoverModel *model1 = [[DiscoverModel alloc]init];
//    model1.imageName = @"shoot";
//    model1.titleName = @"二人游戏";
//    model1.detailName = @"12款游戏";
//    DiscoverModel *model2 = [[DiscoverModel alloc]init];
//    model2.imageName = @"shoot1";
//    model2.titleName = @"应用推荐";
//    model2.detailName = @"大家都在玩啥呢瞧一瞧";
    DiscoverModel *model3 = [[DiscoverModel alloc]init];
    model3.imageName = @"shoot";
    model3.titleName = @"摇一摇";
    model3.detailName = @"摇一摇更多惊喜等你来看，还不赶快行动，屌丝专用模块";
//    [_dataArr addObject:model1];
//    [_dataArr addObject:model2];
    [_dataArr addObject:model3];

}

#pragma mark - 创建tableView
- (void)createTableView
{
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width,ScreenSize.height - 64 - 49) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
}



#pragma mark - tableView协议的方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   static NSString * cellID = @"DisCoverCell";
    DiscoverCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    if (cell == nil) {
        cell = [[DiscoverCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if (_dataArr.count > 0) {
        cell.model = _dataArr[indexPath.row];
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0){
        ShootViewController *svc = [[ShootViewController alloc]init];
        svc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:svc animated:YES];
    }else{
        NSString *flag = @"";
        if (indexPath.row  == 1) {
            flag = @"1";
        }else{
            flag = @"0";
        }
        GameViewController *gvc = [[GameViewController alloc]init];
        gvc.hidesBottomBarWhenPushed = YES;
        gvc.flag = flag;
        [self.navigationController pushViewController:gvc animated:YES];
    }
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 75;
}

@end
